#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.IO;
#endregion

namespace Tomahawk.Runtime.Audio
{
    /// <summary>
    /// This is the audio manager of the game
    /// </summary>
    public class AudioManager
    {

        Dictionary<string, AudioPackage> audioPackages;

        /// <summary>
        /// Constructor
        /// </summary>
        public AudioManager()
        {
            audioPackages = new Dictionary<string, AudioPackage>();
        }

        /// <summary>
        /// Load Audio and
        /// </summary>
        public AudioPackage LoadAudioPackage(string packageId, string baseFolder, string engineFileName, string waveBank, string soundBank)
        {

            //create the package
            AudioPackage package = new AudioPackage();
            package.Load(Path.Combine(baseFolder, engineFileName + ".xgs"),
                         Path.Combine(baseFolder, waveBank + ".xwb"),
                         Path.Combine(baseFolder, soundBank + ".xsb"));

            //register the package
            this.audioPackages.Add(packageId, package);

            //return the package created
            return package;
        }

        /// <summary>
        /// Return an audio package already created, if its exists.
        /// </summary>
        public AudioPackage GetAudioPackage(string packageId)
        {
            AudioPackage retVal = null;
            try
            {
                retVal = audioPackages[packageId];
            }
            catch (Exception) { }
            return retVal;
        }
        
        /// <summary>
        /// Unloads an audiopackage
        /// </summary>
        public void UnloadAudioPackage(string p)
        {
            AudioPackage audio = this.GetAudioPackage(p);
            if (audio != null)
            {
                this.audioPackages.Remove(p);
                audio.Unload();
            }
        }

    }

}


